<?php

/**
 * string utility
 */
class Nuo_Utility_String
{
    const RANDOM_TYPE_ALNUM = 1;

    /**
     * get random string
     * @param int $length
     * @param int $type
     * @return $string
     */
    static public function createRandomString($length = 8, $type = 1)
    {
        $string = '';
        $result = '';

        switch($type)
        {
            case 1 :
            default :
                $string = '1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm';
        }
        $max = strlen($string) - 1;
        for ($i = 0; $i < $length; ++$i)
        {
            $result .= substr($string, mt_rand(0, $max), 1);
        }
        return $result;
    }

    /**
     * replace all white space to slug
     * @param string $string
     * @return tring
     */
    static public function toSlug($string)
    {
        return preg_replace('#\s+#', '-', $string);
    }
}